<script setup lang="ts">
import { ref } from "vue";
import ReCol from "@/components/ReCol";
import { formRules } from "../utils/rule";
import { FormProps } from "../utils/types";
import { usePublicHooks } from "../../hooks";

const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    name: "",
    title:'',
    apiPath: '',
    method: '',
    status: 1,
    remark: "",
         
  })
});

const requestOptions = [
  {
    value: 'GET',
    label: "GET"
  },
  {
    value: 'POST',
    label: "POST"
  },
    {
    value: 'PUT',
    label: "PUT"
  },
    {
    value: 'DELETE',
    label: "DELETE"
  },
  {
    value:'PATCH',
    label:'PATCH'
  }

];

const ruleFormRef = ref();
const { switchStyle } = usePublicHooks();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    :rules="formRules"
    label-width="82px"
  >
    <el-row :gutter="30">
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="接口名" prop="name">
          <el-input
            v-model="newFormInline.nickname"
            clearable
            placeholder="请输入接口名"
          />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="接口路径" prop="apiPath">
          <el-input
            v-model="newFormInline.username"
            clearable
            placeholder="请输入接口路径"
          />
        </el-form-item>
      </re-col>

      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="请求方式">
          <el-select
            v-model="newFormInline.sex"
            placeholder="请选择请求方式"
            class="w-full"
            clearable
          >
            <el-option
              v-for="(item, index) in requestOptions"
              :key="index"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
      </re-col>

      <re-col
        :value="12"
        :xs="24"
        :sm="24"
      >
        <el-form-item label="接口状态">
          <el-switch
            v-model="newFormInline.status"
            inline-prompt
            :active-value="1"
            :inactive-value="0"
            active-text="启用"
            inactive-text="停用"
            :style="switchStyle"
          />
        </el-form-item>
      </re-col>

      <re-col>
        <el-form-item label="备注">
          <el-input
            v-model="newFormInline.remark"
            placeholder="请输入备注信息"
            type="textarea"
          />
        </el-form-item>
      </re-col>
    </el-row>
  </el-form>
</template>
